//    Copyright (C) Kherty.  All rights reserved.
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.Contracts;

namespace OpenLS.Spreadsheet.Internals
{
    public class ColumnGroup : ChildGroup
    {
        public static ColumnGroup CreateColumnGroupWithNext(Group parent, Column first, Column next)
        {
            return new ColumnGroup(parent, first, (Column)next.GetPrevious());
        }
#if DEBUG
        public override string ToString()
        {
            return this.First.Label + " " + Last.Label;
        }
#endif
        public static ColumnGroup CreateColumnGroupWithLast(Group parent, Column first, Column last)
        {
            return new ColumnGroup(parent, first, last);
        }
        private ColumnGroup(Group parent, Column first, Column last)
            : base(parent, first, last)
        {
            Contract.Requires(!(parent is RowRootGroup));
        }

        protected override void NotifyTotalChanged()
        {
            NotifyPropertyChanged("TotalWidth");
        }


        internal override IEnumerable<Dimension> GetDimensions(bool includeNext)
        {
            for (int i = First.Index; i <= Last.Index; i++)
            {
                yield return First.Worksheet.Columns[i];
            }
            if (includeNext)
                yield return Next;
        }
        public Column Next { get { return Last.Worksheet.Columns[Last.Index + 1]; } }
        public double TotalWidth { get { return Next.Offset - First.Offset + ((Column)Next).ActualWidth; } }
        protected override Dimension GetDimension(int i)
        {
            return First.Worksheet.Columns[i];
        }
    }
}
